package koction.model.question;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import koction.model.consumer.ConsumerVO;
import koction.model.seller.SellerVO;

import org.springframework.stereotype.Service;

@Service
public class QuestionBoardServiceImpl implements QuestionBoardService {

	@Resource(name="questionBoardDaoImpl")
	private QuestionBoardDao dao;	
	
	@Override
	public ListVO getQuestionBoardList(String pageNo) throws SQLException {
		if(pageNo==null||pageNo=="") 
			pageNo="1";
		List<QuestionBoardVO> list=dao.getQuestionBoardList(pageNo);
		int total=dao.totalContent();
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		ListVO lvo=new ListVO(list,paging);
		return lvo;
	}

	@Override
	public void writeQuestion(QuestionBoardVO qvo) throws SQLException {
		dao.writeQuestion(qvo);
	}

	@Override
	public QuestionBoardVO showContentQuestionBoard(int no) throws SQLException {
		return dao.showContent(no);
	}

	@Override
	public QuestionBoardVO showContent(int no,int count) throws SQLException {
		HashMap<String, Integer> map=new HashMap<String, Integer>();
		map.put("no", no);
		map.put("count", count);
		dao.updateCount(map);
		return dao.showContent(no);
	}

	@Override
	public void deleteQuestionBoard(int no) throws SQLException {
		dao.deleteQuestionBoard(no);	
	}

	@Override
	public void deleteSellerQuestionBoard(SellerVO svo) throws SQLException {
		dao.deleteSellerQuestionBoard(svo);	
	}
	
	@Override
	public void updateQuestionBoard(QuestionBoardVO qvo) throws SQLException {
		dao.updateQuestionBoard(qvo);
	}

	@Override
	public void writeReplyQuestionBoard(QuestionBoardVO qvo) throws SQLException {
		int ref = qvo.getRef();
		int restep = qvo.getRestep();
		int relevel = qvo.getRelevel();
		dao.updateRestep(ref, restep);
		qvo.setRestep(restep+1);
		qvo.setRelevel(relevel+1);
		dao.writeReplyQuestionBoard(qvo);
	}

	@Override
	public String getReplyId(QuestionBoardVO qvo) throws SQLException {
		return dao.getReplyId(qvo);
	}

	@Override
	public String replyCheck(String ref) throws SQLException {
		return dao.replyCheck(ref);
	}

	@Override
	public void deleteReplyQuestion(ConsumerVO cvo) throws SQLException {
		dao.deleteReplyQuestion(cvo);
		
	}

}
